-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add a default home page #16
Conversation
f37bc9f
to
0f3779c
Compare
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<!-- Latest compiled and minified CSS --> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we skip out on loading the full bootstrap.min.css
and the accompanying js
file? We're using about 2 styles from this entire file. I'd rather we copy the style in-lined for a faster render. No JS is needed. (Currently this + JS is loading 63.1 KB while the page payload is only 1.7 KB).
An alternative IIRC is that BootStrap also provides just the grid
CSS -- which is lighter and includes the CSS for container
class.
</footer> | ||
<!-- Bootstrap core JavaScript --> | ||
<!-- Placed at the end of the document so the pages load faster --> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing on this page needs the JS ... no BootStrap widgets are used.
<div class="container"> | ||
<h1>${this.name}@${this.version}</h1> | ||
<ul> | ||
<li><a href="/openapi.json">OpenAPI spec: /openapi.json</a></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we style the list to be bigger. Plus can OpenAPI spec:
not be part of the link. Bolded. Would be a better style imo.
Same applies for the bullet below.
</div> | ||
<footer> | ||
<div class="container"> | ||
<p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's center this text on the page.
@virkt25 You worked around the issue by manipulating Express response directly. In this case, we should introduce a special return value such as Feel free to improve the UI. I'm a beginner there :-). |
I think a simpler fix can even be just to check if And of course in the long term it should request the
I'll push some changes to the PR in a bit :) |
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
4667561
to
2258e98
Compare
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
Please note that the CI failure is not related to this change. It will be fixed as part of #14. |
f1cc2bb
to
23da6cb
Compare
Here's a screenshot for the UI -- no external CSS / JS. Minor variances with some alternatives below. I personally vote for Alternative 1 (I tried it after pushing my changes otherwise I would've included that in the PR). Anyone else have any preferences? cc: @raymondfeng @bajtos @strongloop/sq-lb-apex Current:
|
…type We discover an issue to return html from a controller: See loopbackio/loopback4-example-shopping#16
I vote for Alternative 1. Perhaps instead of using A mock-up:
@loopback/example-shopping
|
public/index.html.template
Outdated
<body> | ||
<h1 style="text-align: center">${name}@${version}</h1> | ||
<h3>OpenAPI spec: <a href="/openapi.json">/openapi.json</a></h4> | ||
<h3>API Explorer: <a href="/explorer">/explorer</a></h4> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, applications can customize the URL of both OpenAPI spec and Explorer. See loopbackio/loopback-next#1637, Customize How OpenAPI Spec is Served and Configure the API Explorer.
IMOL, the home page should respect these settings. Eventually :) I am fine to keep the current static version as the first baby step.
description: string; | ||
render: TemplateExecutor; | ||
|
||
constructor(@inject(RestBindings.Http.RESPONSE) private res: Response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use response
instead of res
please?
import {inject} from '@loopback/context'; | ||
import {RestBindings, Response} from '@loopback/rest'; | ||
|
||
const pkg = require('../../../package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the perspective of clean design and Dependency Injection pattern, I think controller should not depend package.json
directly, but get it injected from app context. Then the application should bind the content of package.json
(maybe a subset of properties only?) in its constructor.
Not a big deal for this particular pull request, but I think we should think more about the design patterns when we start working on adding HomePageController to our project template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm thinking about the same direction while I work on this implementation.
Signed-off-by: Raymond Feng <[email protected]>
Signed-off-by: Raymond Feng <[email protected]>
Signed-off-by: Raymond Feng <[email protected]>
Signed-off-by: virkt25 <[email protected]>
Signed-off-by: Raymond Feng <[email protected]>
7cfc221
to
226347d
Compare
Signed-off-by: Raymond Feng <[email protected]>
366433c
to
5334669
Compare
Signed-off-by: Raymond Feng <[email protected]>
5334669
to
df3c287
Compare
Add a default home page for the app. We'll use it as a template for loopbackio/loopback-next#1745.
We need to fix
@loopback/rest
so that it respects the correctcontent-type
fromresponses
. At the moment, the home page will render raw html as the media type isplain/text
for string response from the controller method.